#!/bin/bash
IP=baidu.com
dir="/tools/netdir/"
if [ -d ${dir} ];then
	mkdir -p ${dir}
fi
while true
do
	data=`date +%F' '%H:%M`
	data1=`date +%F' '%H:%M:%S`
	echo "------------${data1}---------------">>${dir}ping.log
	ping -c 5 ${IP} >>${dir}ping.log
	sleep 5
	
	Time=`date +%F`
	TIME="${Time} 23:59"
	if [ "${data}" == "${TIME}" ];then
		mkdir ${dir}${Time} && mv ${dir}ping.log ${dir}${Time}-ping.log
		mv ${dir}${Time}-ping.log ${dir}${Time}
	fi
	find ${dir} -mtime +7 -name "*-ping.log" -exec rm -rf {} \;
done

